package foo.bar.db.Dao.impl;

import foo.bar.db.Dao.EmployeeDao;
import foo.bar.db.entity.Employee;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MongoEmployeeDao implements EmployeeDao {

    @Autowired
    MongoTemplate template;

    @Override
    public void save(Employee employee) {
        template.save(employee);
    }

    @Override
    public List<Employee> findEmployeeById() {
        return template.findEmployeeById(Employee.class);
        System.out.println("The list " employee);
        
    }

    public Employee findById(String id) {
        return template.findOne(new Query(new Criteria("_id").is(new ObjectId(id))), Employee.class);
    }
}
